class RoleDescriptionsController < ApplicationController
  before_filter :get_role_and_laiv
  # GET /role_descriptions
  # GET /role_descriptions.xml
  def index
    @role_descriptions = @role.role_descriptions.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @role_descriptions }
    end
  end

  # GET /role_descriptions/1
  # GET /role_descriptions/1.xml
  def show
    @role_description = @role.role_descriptions.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @role_description }
    end
  end

  # GET /role_descriptions/new
  # GET /role_descriptions/new.xml
  def new
    @role_description = @role.role_descriptions.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @role_description }
    end
  end

  # GET /role_descriptions/1/edit
  def edit
    @role_description = @role.role_descriptions.find(params[:id])
  end

  # POST /role_descriptions
  # POST /role_descriptions.xml
  def create
    @role_description = @role.role_descriptions.new(params[:role_description])

    respond_to do |format|
      if @role_description.save
        flash[:notice] = 'RoleDescription was successfully created.'
        format.html { redirect_to([@laiv, @role, @role_description]) }
        format.xml  { render :xml => @role_description, :status => :created, :location => @role_description }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @role_description.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /role_descriptions/1
  # PUT /role_descriptions/1.xml
  def update
    @role_description = @role.role_descriptions.find(params[:id])

    respond_to do |format|
      if @role_description.update_attributes(params[:role_description])
        flash[:notice] = 'RoleDescription was successfully updated.'
        format.html { redirect_to([@laiv, @role, @role_description]) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @role_description.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /role_descriptions/1
  # DELETE /role_descriptions/1.xml
  def destroy
    @role_description = @role.role_descriptions.find(params[:id])
    @role_description.destroy

    respond_to do |format|
      format.html { redirect_to(laiv_role_role_descriptions_url(@laiv, @role)) }
      format.xml  { head :ok }
    end
  end

  private

  def get_role_and_laiv
    @laiv = Laiv.find(params[:laiv_id])
    @role = @laiv.roles.find(params[:role_id])
  end
end
